<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入react核心库 -->
	<script type="text/javascript" src="../../js/react.development.js"></script>
	<!-- 引入react-dom，用于支持react操作DOM -->
	<script type="text/javascript" src="../../js/react-dom.development.js"></script>
	<!-- 引入babel，用于将jsx转为js -->
	<script type="text/javascript" src="../../js/babel.min.js"></script>
</head>

<body>
    <div id="root"></div>
    <!-- 注意：js的类型type="text/babel" -->
    <script  type="text/babel">
        function FormatData(props){
            return <h2>
                It is {props.date.toLocaleTimeString()}
                </h2>
        }

        class Clock extends React.Component{
            // 1
            constructor(props){
                super(props);
                this.state={
                    date:new Date()
                }
            }
            // 2
            render(){
                return (
                    <div>
                        <h1>hello world</h1>
                        <FormatData date={this.state.date}/>
                    </div>
                    
                )
            }
            componentDidMount(){
                this.timeId=setInterval(()=>{
                    this.tick();
                },1000);
            }
            tick(){
                this.setState({
                    date:new Date()
                })
            }
            componentWillUnmount(){
                clearInterval(this.timeId);
            }
        }
        // 0
        ReactDOM.render(
            <div>
                <Clock/>
                <Clock/>
                <Clock/>
            </div>,
            document.getElementById('root')
        )
    </script>
</body>

</html>